using Npgsql;
using admin.core.Repositories;
using admin.infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using System.Data;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using admin.infrastructure.Repositories;

public static class ServicesCollectionExtension
{
  public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration couiguration)
    {
        var connectionString = couiguration.GetConnectionString("pgsql");

        services.AddDbContext<DemoDbContext>(x =>
        {
            x.UseNpgsql(connectionString);
        });

        // 注册IDbConnection，每次请求创建新的连接
        services.AddScoped<IDbConnection>(sp => new NpgsqlConnection(connectionString));

        return services;
    }
}